<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <title>智能组卷系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="app-container">
        <div class="box2">

            <!-- 左侧 -->
            <div class="left-container">
                <div class="left-top-section">
                    <el-button type="primary" class="dalfBut" @click="newModel()" style="width: 200px">新建模板</el-button>
                    <br>
                    <el-button type="success" class="dalfBut" @click="selectModel()" style="width: 200px">选择模板
                    </el-button>
                    <br>
                    <el-button type="warning" class="dalfBut" @click="selectChapter()" style="width: 200px">章节范围
                    </el-button>
                    <br>
                    <el-button type="danger" class="dalfBut" @click="selectDifficulty()" style="width: 200px">难度与模式
                    </el-button>
                </div>
                <div class="left-bottom-section">
                    <button class="paper-button" @click="generatePaper()">开始组卷</button>
                </div>
            </div>

            <!-- 右侧 -->
            <div class="right-container">
                <div class="right-top-section">
                    <el-table size="small" current-row-key="id" row-height="60px" :data="dataList" border>
                        <el-table-column type="index" align="center" min-width="50px" width="50px"
                                         label="题号"></el-table-column>
                        <el-table-column label="题干" align="center" min-width="200px">
                            <template slot-scope="scope">
                                <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
                                    {{scope.row.question }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="答案" align="center" min-width="150px">
                            <template slot-scope="scope">
                                <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
                                    {{scope.row.answer }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="score" label="分值" align="center" min-width="50px">
                            <template slot-scope="scope">
                                {{ scope.row.score}}分
                            </template>
                        </el-table-column>
                        <el-table-column prop="type" label="类型" align="center" min-width="70px"></el-table-column>

                        <el-table-column prop="difficulty" label="难度" align="center" min-width="50px"></el-table-column>
                        <el-table-column prop="requirement" label="要求" align="center"
                                         min-width="50px"></el-table-column>

                        <el-table-column prop="knowledge" label="知识点" align="center"
                                         min-width="130px">
                            <template slot-scope="scope">
                                <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
                                    {{scope.row.knowledge}}
                                </div>
                            </template>
                        </el-table-column>

                        <el-table-column label="操作" align="center" min-width="100px" width="100px">
                            <template slot-scope="scope">
                                <el-button plain type="text" size="mini" @click="handleUpdate(scope.row)">
                                    详情
                                </el-button>
                                <el-button plain type="text" size="mini" @click="handleReplace(scope.row)"
                                           style="color: red;">
                                    替换
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="right-bottom-section">
                    <el-input v-model="formData.name" style="width: 500px" placeholder="请输入试卷名"></el-input>
                    <el-button class="dalfBut" @click="savePaper() " size="medium" style="margin-left:15px ">保存
                    </el-button>
                    <el-button class="dalfBut" @click="resetPaper()" size="medium">重置</el-button>
                    <el-button type="primary" class="dalfBut" @click="lookPaper()" size="medium">详情</el-button>
                    <el-button type="warning" class="butT" @click="exportPaper()" size="medium">导出</el-button>
                </div>
            </div>

            <!-- 新增模板 -->
            <div class="add-form">
                <el-dialog title="新建模板" :visible.sync="addFormVisible">
                    <el-form ref="dataAddForm" :model="modelFormData" label-position="right">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="模板名称" prop="name" label-width="100px">
                                    <el-input v-model="modelFormData.name" placeholder="未命名"/>
                                </el-form-item>
                            </el-col>

                            <el-col :span="12">
                                <el-form-item label="试卷总分" prop="score" label-width="100px">
                                    <el-input v-model="modelFormData.score" placeholder="100"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="选择题:题数" prop="choiceNumber" label-width="115px">
                                    <el-input v-model="modelFormData.choiceNumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label=" 总分" prop="choiceScore" label-width="60px">
                                    <el-input v-model="modelFormData.choiceScore"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="填空题:题数" prop="fillNumber" label-width="115px">
                                    <el-input v-model="modelFormData.fillNumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label=" 总分" prop="fillScore" label-width="60px">
                                    <el-input v-model="modelFormData.fillScore"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="判断题:题数" prop="judgmentNumber" label-width="115px">
                                    <el-input v-model="modelFormData.judgmentNumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label=" 总分" prop="judgmentScore" label-width="60px">
                                    <el-input v-model="modelFormData.judgmentScore"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="简答题:题数" prop="shortAnswerNumber" label-width="115px">
                                    <el-input v-model="modelFormData.shortAnswerNumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label=" 总分" prop="shortAnswerScore" label-width="60px">
                                    <el-input v-model="modelFormData.shortAnswerScore"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="计算题:题数" prop="calculationNumber" label-width="115px">
                                    <el-input v-model="modelFormData.calculationNumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label=" 总分" prop="calculationScore" label-width="60px">
                                    <el-input v-model="modelFormData.calculationScore"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="其它题:题数" prop="otherNumber" label-width="115px">
                                    <el-input v-model="modelFormData.otherNumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label=" 总分" prop="otherScore" label-width="60px">
                                    <el-input v-model="modelFormData.otherScore"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>

                    <div slot="footer" class="dialog-footer">
                        <el-button @click="addFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 选择模板-->
            <div class="add-form">
                <el-dialog title="选择模板" :visible.sync="modelFormVisible" width="963px" :close-on-click-modal="false"
                           append-to-body>
                    <div class="el-dialog-div2">
                        <el-form ref="dataAddForm" :model="formData" label-position="right">
                            <el-table size="small" current-row-key="id" min-row-height="40px" :data="modelList" border>
                                <el-table-column label="模板名" align="center" min-width="200px" width="200px">
                                    <template slot-scope="scope">
                                        <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
                                            {{scope.row.name }}
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="score" label="总分" min-width="60px" width="60px"
                                                 align="center"></el-table-column>

                                <el-table-column label="选择题" align="center">
                                    <el-table-column prop="choiceNumber" label="题数" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                    <el-table-column prop="choiceScore" label="总分" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                </el-table-column>
                                <el-table-column label="填空题" align="center">
                                    <el-table-column prop="fillNumber" label="题数" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                    <el-table-column prop="fillScore" label="总分" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                </el-table-column>
                                <el-table-column label="判断题" align="center">
                                    <el-table-column prop="judgmentNumber" label="题数" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                    <el-table-column prop="judgmentScore" label="总分" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                </el-table-column>
                                <el-table-column label="简答题" align="center">
                                    <el-table-column prop="shortAnswerNumber" label="题数" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                    <el-table-column prop="shortAnswerScore" label="总分" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                </el-table-column>
                                <el-table-column label="计算题" align="center">
                                    <el-table-column prop="calculationNumber" label="题数" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                    <el-table-column prop="calculationScore" label="总分" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                </el-table-column>
                                <el-table-column label="其它题" align="center">
                                    <el-table-column prop="otherNumber" label="题数" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                    <el-table-column prop="otherScore" label="总分" align="center"
                                                     min-width="50px" width="50px"></el-table-column>
                                </el-table-column>

                                <el-table-column label="操作" align="center" min-width="60px" width="60px">
                                    <template slot-scope="scope">
                                        <el-button plain type="text" size="mini" @click="handleSelect(scope.row)"
                                                   style="color: red;">
                                            选择
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>

                        </el-form>
                    </div>

                    <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="modelFormVisible = false">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 难度系数表单 -->
            <div class="add-form">
                <el-dialog title="难度与模式" :visible.sync="diffFormVisible" width="500px">
                    <el-form ref="dataAddForm" :model="formData" label-position="right">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="期望难度" prop="difficulty" label-width="100px">
                                    <el-input v-model="formData.difficulty"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="组卷方法" label-width="100px">
                                    <el-select v-model="method" clearable>
                                        <el-option label="标准模式" value="1"></el-option>
                                        <el-option label="精确模式" value="2"></el-option>
                                        <el-option label="快速模式" value="3"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label-width="100px">
                                    <el-radio v-model="repeat" label="true" @change="handleChange">减少近年相似题目</el-radio>
                                    <el-radio v-model="repeat" label="false" @change="handleChange">无限制</el-radio>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>

                    <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="diffFormVisible = false">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 章节范围表单 -->
            <div class="add-form">
                <el-dialog title="设定章节" :visible.sync="chapterFormVisible" :close-on-click-modal="false" append-to-body>
                    <div class="el-dialog-div2">
                        <el-form ref="dataAddForm" :model="formData" label-position="right">
                            <el-row>
                                <el-col :span="6">
                                    <el-form-item label="最小章节" prop="minChapter" label-width="100px">
                                        <el-input v-model="formData.minChapter" placeholder="章"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label="--" prop="minSection" label-width="35px">
                                        <el-input v-model="formData.minSection" placeholder="节"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label="最大章节" prop="maxChapter" label-width="100px">
                                        <el-input v-model="formData.maxChapter" placeholder="章"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label="--" prop="maxSection" label-width="35px">
                                        <el-input v-model="formData.maxSection" placeholder="节"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label-width="30px">
                                        <el-button class="dalfBut" size="medium" @click="showChapter()">查看</el-button>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-table size="small" current-row-key="id" min-row-height="40px" :data="chapterList"
                                      border>
                                <el-table-column type="index" align="center" label="序号"></el-table-column>
                                <el-table-column label="知识点" prop="knowledge" width="250x"
                                                 align="center"></el-table-column>
                                <el-table-column label="章节" width="80px" min-width="80px" align="center">
                                    <template slot-scope="scope">
                                        {{ scope.row.chapter}}-{{ scope.row.section}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="大纲要求" width="80px" min-width="80px" align="center">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.requirement === 'a'">了解</span>
                                        <span v-else-if="scope.row.requirement === 'b'">理解</span>
                                        <span v-else-if="scope.row.requirement === 'c'">掌握</span>
                                        <span v-else-if="scope.row.requirement === 'd'">应用</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="分值权重" prop="proportion" width="80px" min-width="80px"
                                                 align="center"></el-table-column>
                                <el-table-column label="操作" align="center" width="80px" min-width="80px">
                                    <template slot-scope="scope">
                                        <el-button plain type="text" size="mini" @click="modifyProportion(scope.row)"
                                                   style="color: red;">
                                            修改权重
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>

                        </el-form>
                    </div>
                    <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="setChapter()">确定</el-button>
                    </div>

                </el-dialog>
            </div>

            <!-- 修改权重表单 -->
            <div class="add-form">
                <el-dialog title="设定章节分值" :visible.sync="modifyFormVisible" width="300px" :close-on-click-modal="false">
                    <el-form ref="dataAddForm" :model="cFormData" label-position="right">
                        <el-row>
                            <el-col :span="22">
                                <el-form-item label="分值权重" prop="difficulty" label-width="80px">
                                    <el-input v-model="cFormData.proportion" placeholder="0-1间的两位小数"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>

                    <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="setProportion()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 查看表单 -->
            <div class="add-form">
                <el-dialog title="试题内容" :visible.sync="editFormVisible">
                    <el-form ref="dataAddForm" :model="questionFormData" label-position="right" :disabled="true">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="题干" label-width="100px">
                                    <el-input v-model="questionFormData.question" type="textarea" :rows="4"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="答案" label-width="100px">
                                    <el-input v-model="questionFormData.answer" type="textarea" :rows="4"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-dialog>
            </div>

            <!-- 替换弹窗 -->
            <div class="container-box">
                <el-dialog title="选择题目" :visible.sync="replaceFormVisible" width="1040px" :close-on-click-modal="false"
                           append-to-body
                >
                    <div class="el-dialog-div">
                        <el-form ref="dataAddForm" :model="replaceFormData" label-position="right">
                            <el-row>
                                <el-col :span="6">
                                    <el-form-item label="题干" label-width="100px">
                                        <el-input v-model="replaceFormData.selectData.question"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="3">
                                    <el-form-item label="章节" label-width="75px">
                                        <el-input v-model="replaceFormData.selectData.chapter" placeholder="章"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="2">
                                    <el-form-item label="--" label-width="30px">
                                        <el-input v-model="replaceFormData.selectData.section" placeholder="节"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label="难度" label-width="75px">
                                        <el-input v-model="replaceFormData.selectData.difficultyMin"
                                                  placeholder="最低难度"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="3">
                                    <el-form-item label="~" label-width="35px">
                                        <el-input v-model="replaceFormData.selectData.difficultyMax"
                                                  placeholder="最高难度"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label=" " label-width="70px">
                                        <el-button @click="handleSelection()" class="dalfBut" type="primary">查询
                                        </el-button>
                                        <el-button @click="resetSelection()" class="dalfBut">重置</el-button>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-table size="small" current-row-key="id" min-row-height="40px" :data="questionList"
                                      border>
                                <el-table-column type="index" align="center" label="序号"></el-table-column>
                                <el-table-column label="题干" prop="question" width="550px"></el-table-column>
                                <el-table-column label="答案" prop="answer" width="250px"></el-table-column>
                                <el-table-column label="章节" width="50px" min-width="50px" align="center">
                                    <template slot-scope="scope">
                                        {{ scope.row.chapter}}-{{ scope.row.section}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="难度" prop="difficulty" width="50px" min-width="50px"
                                                 align="center"></el-table-column>
                                <el-table-column label="操作" width="50px" min-width="50px" align="center">
                                    <template slot-scope="scope">
                                        <el-button plain type="text" size="mini" @click="replace(scope.row)"
                                                   style="color: red;">
                                            替换
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <div class="dialog-footer2">
                                <el-pagination
                                        class="pagination"
                                        @current-change="handleCurrentChange"
                                        :current-page="pagination.currentPage"
                                        :page-size="pagination.pageSize"
                                        layout="total,prev,pager,next,jumper"
                                        :total="pagination.total">
                                </el-pagination>
                            </div>
                        </div>

                    </div>

                </el-dialog>

            </div>

            <!-- 详情弹窗 -->
            <div class="add-form">
                <el-dialog title="题型分值占比" :visible.sync="detailFormVisible"
                           :close-on-press-escape="false"
                           :close-on-click-modal="false">
                    <el-form ref="dataAddForm" :model="detailFormData" label-position="right" :disabled="true">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="难度系数" label-width="100px">
                                    <el-input v-model="detailFormData.difficulty" :disabled="true"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="试卷总分" label-width="100px">
                                    <el-input v-model="detailFormData.totalScore" :disabled="true"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>

                    <div ref="chart" style="width: 100%; height: 400px;"></div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios.min.js"></script>
<script src="/webjars/echarts/4.9.0/echarts.min.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            formData: {
                maxChapter: "",
                minChapter: "",
                maxSection: "",
                minSection: "",
                difficulty: "",
                modelId: "",
                name: "未命名",
            },
            modelFormData: {
                name: "",
                score: "",
                choiceNumber: "",
                choiceScore: "",
                fillNumber: "",
                fillScore: "",
                shortAnswerNumber: "",
                shortAnswerScore: "",
                calculationNumber: "",
                calculationScore: "",
                judgmentNumber: "",
                judgmentScore: "",
                otherScore: "",
                otherNumber: "",
            },
            questionFormData: {},
            replaceFormData: {
                selectData: {
                    question: "",
                    difficultyMin: "",
                    difficultyMax: "",
                    answer: "",
                    chapter: "",
                    section: ""
                },
                question: "",
                difficulty: "",
                answer: "",
                chapter: "",
                section: ""
            },
            detailFormData: {
                difficulty: "",
                totalScore: "",
            },
            cFormData: {
                proportion: "",
            },

            ques: {},
            row0: {},

            pagination: {
                currentPage: 1,  //当前页码
                pageSize: 4,    //每页记录
                total: 0,        //总记录
            },

            dataList: [],//当前页要展示的列表数据
            modelList: [],
            questionList: [],
            chapterList: [],

            addFormVisible: false,
            modelFormVisible: false,
            diffFormVisible: false,
            chapterFormVisible: false,
            detailFormVisible: false,
            editFormVisible: false,
            replaceFormVisible: false,
            modifyFormVisible: false,
            method: null,
            repeat: "",
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            const userInfo = window.localStorage.getItem('userInfo')
            if (userInfo) {
                this.userInfo = JSON.parse(userInfo)
            }
        },

        methods: {
            //组卷
            generatePaper() {
                if (
                    this.formData.maxChapter === "" ||
                    this.formData.minChapter === "" ||
                    this.formData.maxSection === "" ||
                    this.formData.minSection === "" ||
                    this.formData.difficulty === "" ||
                    this.formData.modelId === "" ||
                    this.method === null ||
                    this.repeat === ""
                ) {
                    this.$message.error("请完善组卷条件");
                } else {
                    let postData = {
                        repeat: this.repeat,
                        formData: this.formData,
                        chapterList: this.chapterList,
                        method: this.method,
                    }
                    axios.post("/paper/generate", postData).then((res) => {

                        if (res.data.code === 30040) {
                            this.dataList = res.data.data;
                            this.$message.success("组卷成功");
                        } else {
                            this.$message.error(res.data.msg);
                        }
                    }).finally(() => {
                    });
                }
            },

            //导出
            exportPaper() {
                console.log(this.dataList)
                console.log(this.formData);
                if (this.dataList.length === 0) this.$message.error("请先组卷");
                else {
                    let postData = {
                        formData: this.formData,
                        dataList: this.dataList
                    }
                    axios.post("/paper/export", postData).then((res) => {
                        console.log(res)
                        if (res.data.code === 30030) {
                            this.$message.success(res.data.msg);
                        } else {
                            this.$message.error(res.data.msg);
                        }
                    });
                }
            },

            //保存
            savePaper() {
                var idList = this.dataList.map(item => item.id);
                console.log(this.userInfo.username)
                this.formData.author = this.userInfo.username
                axios.post("/paper/save", this.formData).then((response) => {
                    if (response.data.code === 20010) {
                        idList.unshift(response.data.data);
                        axios.post("/paper/saveAll", idList).then((res) => {
                            if (res.data.code === 20010) {
                                this.$message.success("添加成功");
                            } else {
                                this.$message.error(res.data.msg);
                            }
                        });
                    } else {
                        this.$message.error(response.data.msg);
                    }
                });
            },

            //详情
            lookPaper(row) {
                let postData = {
                    formData: this.formData,
                    dataList: this.dataList
                }

                axios.post("/paper/details", postData).then((res) => {
                    console.log(res)
                    if (res.data.code === 20040) {
                        this.detailFormVisible = true;

                        // 处理数据
                        const data = [];
                        for (let key in res.data.data) {
                            if (key !== "difficulty" && key !== "totalScore") {
                                data.push({
                                    name: key,
                                    value: res.data.data[key],
                                });
                            } else if (key === "difficulty") {
                                this.detailFormData.difficulty = res.data.data[key]
                            } else {
                                this.detailFormData.totalScore = res.data.data[key]
                            }
                        }
                        // 绘制饼状图
                        this.$nextTick(() => {
                            console.log(this.$refs.chart)
                            this.chartData = echarts.init(this.$refs.chart);
                            this.chartData.setOption({
                                series: [{
                                    name: '章节题型占比',
                                    type: 'pie',
                                    radius: '55%',
                                    center: ['50%', '50%'],
                                    label: {
                                        formatter: '{b}: {d}%'
                                    },
                                    data: data
                                }]
                            });
                        });
                    } else {
                        this.$message.error("操作失败");
                    }
                });

            },

            //弹出添加模板弹窗
            newModel() {
                this.addFormVisible = true;
            },

            //添加模板
            handleAdd() {
                axios.post("/model", this.modelFormData).then((res) => {
                    if (res.data.code === 20010) {
                        this.addFormVisible = false;
                        this.$message.success("添加成功");
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
            },

            //弹出选择模板表单
            selectModel() {
                axios.get("/model").then((res) => {
                    this.modelList = res.data.data;
                    this.modelFormVisible = true;
                });
            },

            //选择模板
            handleSelect(row) {
                this.formData.modelId = row.id;
                this.$message.success("已选择模板[" + row.name + "]");
            },

            //弹出选择章节表单
            selectChapter() {
                this.chapterFormVisible = true;
            },

            //弹出选择难度表单
            selectDifficulty() {
                this.diffFormVisible = true;
            },

            //重置
            resetPaper() {
                this.formData.modelId = "";
                this.formData.maxChapter = "";
                this.formData.maxSection = "";
                this.formData.minChapter = "";
                this.formData.minSection = "";
                this.formData.difficulty = "";
                this.formData.name = "";
                this.dataList = [];
                this.formData.method = "";
                this.chapterList = [];
                this.repeat = "";
            },

            //查看
            handleUpdate(row) {
                axios.get("/questions/" + row.id).then((res) => {
                    if (res.data.code === 20040) {
                        this.questionFormData = res.data.data;
                        this.editFormVisible = true;
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
            },

            //替换
            handleReplace(row) {
                this.replaceFormVisible = "true";
                this.pagination.currentPage = 1;
                this.ques = row
                this.getQuestions();
            },

            getQuestions() {
                param = "?type=" + this.ques.type;
                param += "&question=" + this.replaceFormData.selectData.question;
                param += "&chapter=" + this.replaceFormData.selectData.chapter;
                param += "&section=" + this.replaceFormData.selectData.section;
                param += "&difficultyMin=" + this.replaceFormData.selectData.difficultyMin;
                param += "&difficultyMax=" + this.replaceFormData.selectData.difficultyMax;
                console.log(param)
                axios.get("/questions/" + this.pagination.currentPage + "/" + this.pagination.pageSize + param).then((res) => {
                    this.pagination.pageSize = res.data.data.size;
                    this.pagination.currentPage = res.data.data.current;
                    this.pagination.total = res.data.data.total;
                    this.questionList = res.data.data.records;
                });
            },
            //搜索
            handleSelection() {
                this.getQuestions();
            },

            //重置搜索框
            resetSelection() {
                this.replaceFormData.selectData.question = "";
                this.replaceFormData.selectData.difficultyMin = "";
                this.replaceFormData.selectData.difficultyMax = "";
                this.replaceFormData.selectData.answer = "";
                this.replaceFormData.selectData.chapter = "";
                this.replaceFormData.selectData.section = "";
                this.getQuestions();
            },

            replace(row) {
                let existingQuestion = this.dataList.find(item => item.id === row.id);
                if (existingQuestion) {
                    this.$message.error("该试题已存在");
                } else {
                    let index = this.dataList.findIndex(item => item.id === this.ques.id);
                    this.ques.question = row.question;
                    this.ques.answer = row.answer;
                    this.ques.difficulty = row.difficulty;
                    this.ques.chapter = row.chapter;
                    this.ques.section = row.section;
                    this.ques.id = row.id;
                    this.findRequirement(row);
                    this.findKnowledge(row);
                    if (index !== -1) {
                        this.dataList.splice(index, 1, this.ques);
                    }
                    console.log(this.dataList)
                    this.$message.success("替换成功");
                    this.replaceFormVisible = false;
                }
            },

            //分页
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.getQuestions()
            },
            findRequirement(row) {
                axios.get("/chapter/requirement/" + row.chapter + "/" + row.section).then((res) => {
                    if (res.data.code === 20040) {
                        this.ques.requirement = res.data.data;
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
            },
            findKnowledge(row) {
                axios.get("/chapter/knowledge/" + row.chapter + "/" + row.section).then((res) => {
                    if (res.data.code === 20040) {
                        this.ques.knowledge = res.data.data;
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
            },
            showChapter() {
                if (
                    this.formData.maxChapter === "" ||
                    this.formData.minChapter === "" ||
                    this.formData.maxSection === "" ||
                    this.formData.minSection === ""
                ) {
                    this.$message.error("章节范围不可为空");
                } else {
                    axios.post("/chapter", this.formData).then((res) => {
                        if (res.data.code === 20040) {
                            this.chapterList = res.data.data;
                        } else {
                            this.$message.error(res.data.msg);
                        }
                    });
                }
            },
            modifyProportion(row) {
                this.modifyFormVisible = true;
                this.row0 = row;
            },
            setChapter() {
                if (this.chapterList.length === 0) {
                    this.showChapter();
                }
                this.chapterFormVisible = false;
            },

            setProportion() {
                const p = parseFloat(this.cFormData.proportion);
                if (isNaN(p) || p < 0) {
                    this.$message.error("请输入正确的分值权重");
                } else if (p > 1.0) {
                    this.$message.error("分值权重不宜过大");
                } else {
                    this.row0.proportion = proportion;
                    this.modifyFormVisible = false;
                }
            },

            handleChange() {
                console.log(this.repeat)
            }
        }
    })
</script>
</html>